package com.may.rabbitmq.provider.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author May
 * @date 2021/04/01 13:24
 */
@Configuration
public class RabbitmqConfig {

    /**
     * 交换机
     * @author mayuanbao
     * @date 2021/04/01 13:27
     * @return org.springframework.amqp.core.FanoutExchange
     */
    @Bean
    public FanoutExchange fanoutExchange() {
        return new FanoutExchange("fanoutExchange", true, false);
    }

    /**
     * 队列
     * @author mayuanbao
     * @date 2021/04/01 13:29
     * @return org.springframework.amqp.core.Queue
     */
    @Bean
    public Queue fanoutQueue() {
        return new Queue("fanoutQueue", true);
    }

    /**
     * 绑定队列和交换机
     * @author mayuanbao
     * @date 2021/04/01 13:31
     * @return org.springframework.amqp.core.Binding
     */
    @Bean
    public Binding fanoutBinding() {
        return BindingBuilder.bind(fanoutQueue()).to(fanoutExchange());
    }
}
